<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>重置密码</title>
    <link rel="stylesheet" href="lib/layui/css/layui.css"/>
</head>
<body>
<div style="padding-top: 20px;padding-right: 40px">
    <form class="layui-form" action="" lay-filter="user">
        <div class="layui-form-item">
            <label class="layui-form-label">登录密码</label>
            <div class="layui-input-block">
                <input type="password" name="password" required lay-verify="required|pass"
                       placeholder="请输入登录密码" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">确认密码</label>
            <div class="layui-input-block">
                <input type="password" name="password2" required lay-verify="required"
                       placeholder="请再次输入登录密码" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="userinfo">确认修改</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/sha.js"></script>
<script type="text/javascript" src="js/jquery.cookie.js"></script>
<script type="text/javascript" src="js/app.js"></script>
<script type="text/javascript" src="lib/layui/layui.js"></script>
<script>
    layui.use(['form','layer'], function () {
        var form = layui.form;
        var layer=layui.layer;
        //监听提交
        form.on('submit(userinfo)', function (data) {
            var field=data.field
            if(field.password!=field.password2){
                layer.msg("两次输入密码不一致")
                return false;
            }
            var userItem={
                pwd:hex_sha1(field.password)
            }
            resetPWD(userItem);

            return false;
        });

        form.verify({
            pass: function (value, item){
                if (!new RegExp("^[\\S]{8,30}$").test(value)) {
                    return '密码必须8到30位，且不能出现空格';
                }
                if (!new RegExp("((?=.*[a-z])(?=.*\\d)|(?=[a-z])(?=.*[#@!~%^&*])|(?=.*\\d)(?=.*[#@!~%^&*]))[a-z\\d#@!~%^&*]{8,30}").test(value)) {
                    return '密码必须包含大写字母、小写字母、数字中至少两种字符组合';
                }
            } ,
            ip: [/^(?:(?:1[0-9][0-9]\.)|(?:2[0-4][0-9]\.)|(?:25[0-5]\.)|(?:[1-9][0-9]\.)|(?:[0-9]\.)){3}(?:(?:1[0-9][0-9])|(?:2[0-4][0-9])|(?:25[0-5])|(?:[1-9][0-9])|(?:[0-9]))$/, 'IP地址格式不正确']
        });
    });

    function resetPWD(userItem) {
        httpPost("admin/update", userItem, function (res) {
            layui.use(['layer'], function () {
                var layer=layui.layer;
                layer.msg(res.msg)
                if(res.code==0){
                    httpPost("admin/exit",{},function(res){
                        top.window.location.href="/index.html"
                    })

                }
            });
        })
    }
</script>
</body>
</html>